package com.bjsxt.controller.system;

import com.bjsxt.config.upload.UploadService;
import com.bjsxt.vo.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

/**
 * 文件上传controller层
 */
@RestController
@RequestMapping("system/upload")
public class UploadController {

    @Autowired
    private UploadService uploadService;

    /**
     * 文件图片【检查结果】
     *
     * @param multipartFile
     * @return
     */
    @PostMapping("doUploadImage")
    public AjaxResult doUploadImage(@Validated MultipartFile multipartFile) {
        Map<String, Object> map = new HashMap<>();
        if (null == map) {
            map.put("name", multipartFile.getOriginalFilename());
            String path = this.uploadService.uploadImage(multipartFile);
            map.put("url", path);
            System.out.println(map);
            return AjaxResult.success(map);
        } else {
            return AjaxResult.fail("上传文件失败");
        }
    }

}
